package com.ccrfid.rmc6.ws.c5.cardreader;

import com.ccrfid.rmc6.service.device.CardreaderService;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.InsertCardReaderRequest;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.InsertCardReaderResponse;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.UploadCardRequest;
import com.ccrfid.rmc6.ws.c5.cardreader.pojo.UploadCardResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

@Endpoint
public class CardReaderEndpoint {
    private static final Logger logger = LoggerFactory.getLogger(CardReaderEndpoint.class);
    private static final String NAMESPACE_URI = "http://WebService.service.ccrfid.com/";

    @Autowired
    private CardreaderService cardreaderService;

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "insertCardReader")
    @ResponsePayload
    public InsertCardReaderResponse insertCardReader(@RequestPayload InsertCardReaderRequest request) {
        logger.debug("insertCardReader ipAddrs: {}", request.getIpAddrs());

        InsertCardReaderResponse response = new InsertCardReaderResponse();
        response.setRet(0);
        return response;
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "uploadCard")
    @ResponsePayload
    public UploadCardResponse uploadCard(@RequestPayload UploadCardRequest request) {
        logger.debug("uploadCard: {}", request);
        cardreaderService.readCard(request);

        UploadCardResponse response = new UploadCardResponse();
        response.setRet(0);
        return response;

    }
}
